段家鑫 10:41:05
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>右键关闭弹出框</title>
		<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
		<script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../js/easyui/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript" src="../js/ztree/jquery.ztree.all-3.5.js" charset="UTF-8"></script>
		<link rel="stylesheet" href="../js/ztree/zTreeStyle.css" />
		<link rel="stylesheet" href="../js/easyui/themes/default/easyui.css" />
		<link rel="stylesheet" href="../js/easyui/themes/icon.css" />
		<script type="text/javascript">
			
			 // 定义当前窗口名
		    var currentTitle;
		    // 定义所有窗口名
		    var allTitle = new Array();
			    
			$(function(){
				
				// 1.对ztree节点设置
				var setting = {
					data:{
						simpleData:{
							// 支持简单的json
							enable:true
						}
					},
				    
				    // 设置树形回掉函数
				   callback: {
						onClick: function(event, treeId, treeNode, clickFlag){
							
							var content = '<div style="width:100%;height:100%;overflow:hidden;">'
								+ '<iframe src="'
								+ treeNode.page
								+ '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>'; 
							
								// 没有page树形菜单，不打开选项卡
								if(treeNode.page != "" && treeNode.page != undefined){
									
									// 获取所有选项卡名
									allTitle.push(treeNode.name);
									
									// 如果选项卡已打开，选中
									if($("#mytabs").tabs('exists',treeNode.name)){
										// 选中选项卡
										$("#mytabs").tabs('select',treeNode.name);
										
									}else{
										// 如果未打开，添加新选项卡
										$("#mytabs").tabs('add',{
											title: treeNode.name,
											content: content,
											closable: true	
										});
									}
								}
							}
						}
				};

			    // 2.设置ztree参数
				var zNodes = [
							{id:1, pId:0, name: "父节点1"},
							{id:2, pId:0, name: "父节点2"},
							{id:11, pId:1, name: "子节点1"},
							{id:12, pId:1, name: "子节点2"},
							{id:21, pId:2, name: "传智播客",page:"http://www.itcast.cn"},
							{id:22, pId:2, name: "百度",page:"https://www.baidu.com"},
						  ]; 
				// 3.生成ztree
			    $.fn.zTree.init($("#tree"), setting, zNodes);
			    
			    // 为弹出框添加右击事件
			    $("#mytabs").tabs({
			    	onContextMenu:function(e, title,index){
			    		
			    		// 获取当前选项卡名
			    		currentTitle = title;
			    		
			    		// 阻止默认框显示
			    		e.preventDefault();
			    		
			    		// 显示自定义弹出框
			    		$('#mm').menu('show', {    
						  left: e.pageX,    
						  top: e.pageY   
						}); 
			    	}			    	
			    });			    
			   
		    	// 关闭当前窗口
			    $("#closeCurrentTabs").click(function(){
			    	$('#mytabs').tabs('close',currentTitle);
			    });
			    
			    // 关闭其他窗口
			    $("#closeOthersTabs").click(function(){
			    	
			    	for(var i = 0;i < allTitle.length;i++){
			    		if(allTitle[i] != currentTitle){
			    			$('#mytabs').tabs('close',allTitle[i])
			    		}
			    	}
			    });
			    
			    // 关闭所有窗口
			    $("#closeAllTabs").click(function(){
		    		for(var i = 0;i < allTitle.length;i++){
			    		$('#mytabs').tabs('close',allTitle[i])
		    		}
			    });
			    
			});
		</script>
	</head>
	<body>
		<body class="easyui-layout">   
	    <div data-options="region:'north',title:'North Title',split:true" style="height:100px;"></div>   
	    <div data-options="region:'south',title:'South Title',split:true" style="height:100px;"></div>   
	    <div data-options="region:'east',iconCls:'icon-reload',title:'East',split:true" style="width:100px;"></div>   
	    <div data-options="region:'west',title:'菜单导航栏',split:true" style="width:200px;">
	    	<!-- 折叠面板 -->
	    	<div   class="easyui-accordion" data-options="fit:true">
	    		<div  data-options="title:'基础菜单'">
	    			<!--通过ZTree制作父子节点-->
	    			<ul id="tree" class="ztree"></ul>
	    			
	    		</div>
	    		<div data-options="title:'系统菜单'">面板二</div>
	    	</div>
	    </div>   
	    <div data-options="region:'center'" style="background:#eee;">
	    	<!--选项卡-->
	    	<div id="mytabs" class="easyui-tabs" data-options="fit:true">
	    		<div data-options="title:'选项卡一',closable:true">选项卡一</div>
	    		<div data-options="title:'选项卡二',closable:true">选项卡二</div>
	    		
	    		<!--弹出框,初始化时都是隐藏的-->
	    		<div id="mm" class="easyui-menu" style="width:120px;">   
				    <div id="closeCurrentTabs">关闭当前窗口</div>   
				    <div id="closeOthersTabs">关闭其他窗口</div>  
				    <!--分割线-->
				    <div class="menu-sep"></div>  
				    <div id="closeAllTabs" data-options="iconCls:'icon-cancel'">关闭所有窗口</div>   
				</div>
	    	</div>
	    	
	    </div>   
	</body>
</html>
